package cn.pattern.demo5;

import java.lang.reflect.Proxy;

/**
 * @auth wzy
 * @date 2023/10/10 16:26
 */
public class IntermedirayFactory {

    public static <T> T create(Object target){
        IntermedirayInvocationHandler invocationHandler = new IntermedirayInvocationHandler();
        invocationHandler.setTarget(target);

        // 生成代理类的实例
        return (T) Proxy.newProxyInstance(target.getClass().getClassLoader()
                ,target.getClass().getInterfaces()
                ,invocationHandler);
    }

}
